package com.xjh.basestudy.designmode.behaviorMode.behaviorMode5_Status.p2_status;

/**
 * @Author XuJianHua
 * @Date 2022/10/4 16:52
 * @Description

 */
public class TrafficLight {

    //交通灯有红灯（禁行）、黄灯（警示）、绿灯（通行） 3种状态
    State state = new Red();//初始状态为红灯

    public void setState(State state) {
        this.state = state;
    }

    //切换为绿灯（通行）状态
    public void switchToGreen() {
        state.switchToGreen(this);
    }

    //切换为黄灯（警示）状态
    public void switchToYellow() {
        state.switchToYellow(this);
    }

    //切换为红灯（禁行）状态
    public void switchToRed() {
        state.switchToRed(this);
    }

}